package com.woniu.airent.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.airent.dto.UserDto;
import com.woniu.airent.mapper.UserDtoMapper;
import com.woniu.airent.service.UserDtoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserDtoServiceImpl implements UserDtoService {
    @Autowired
    UserDtoMapper userDtoMapper;

    @Override
    public UserDto findUserByUserName(String userName) {
        return userDtoMapper.selectUserByUserName(userName);
    }

    @Override
    public Integer addUser(UserDto userDto) {
        return userDtoMapper.insert(userDto);
    }

    @Override
    public UserDto findUserByTel(String userTel) {
        return userDtoMapper.selectUserByTel(userTel);
    }

    @Override
    public Integer addUserDto(String userName, String userPwd, String userTel) {
        return userDtoMapper.insertUser(userName,userPwd,userTel);
    }

    @Override
    public List<UserDto> findUserRolesByUserName(String userName) {
        return userDtoMapper.selectUserRolesByUserName(userName);
    }

    @Override
    public PageInfo findAllUser(String userName, Integer now, Integer pageSize) {
        PageHelper.startPage(now,pageSize);
        List<UserDto> userDtos = userDtoMapper.selectAllUser(userName);
        return new PageInfo(userDtos);
    }

    @Override
    public Integer showMyType(Integer userId) {
        return userDtoMapper.selectUserType(userId);
    }

    @Override
    public Integer banUser(Integer userId) {
        return userDtoMapper.updateUserType(userId);
    }

    @Override
    public Integer unsealUser(Integer userId) {
        return userDtoMapper.unseal(userId);
    }
}
